package af.Action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import af.Form.ActivoForm;
import af.Form.LoginForm;
import af.Form.ResponsableForm;
import af.tools.Credencial;
import af.Class.Activo;
import af.Class.Login;
import af.Class.Responsable;

public class LoginAction extends DispatchAction {
	
	public ActionForward nuevoLogin(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		LoginForm loginForm = (LoginForm) form;

		Login login = new Login();
		return mapping.findForward("inicio");
		
	}
	
	public ActionForward execute(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		LoginForm loginForm = (LoginForm) form;

		Login login = new Login();

		Credencial credencial = new Credencial();
		credencial.setUserName(loginForm.getUsername());
		credencial.setPassword(loginForm.getPassword());

		request.getSession().setAttribute("form",
				login.autentificarUser(credencial));
		if (login.autentificarUser(credencial) == true) {
			HttpSession session = request.getSession(true);
			return mapping.findForward("bien");
		} else {
			return mapping.findForward("mal");
		}
	}

}
